/**
 * 订单投标记录详情
 */
var table = null;
$(document).ready(function () {
    table = $('#myTable').dataTableExtend({
        "ajax": {"url": sysInfo.basePath + "/sc/general/bid/queryBidList.do", "type": "post"},
        "fnServerParams": function (aoData) {
            aoData = $.extend(aoData, {scProductOrderId: $('#mainId').val()});
            return aoData;
        },
        "scrollX": "true",//是否开启横项滚动
        "fixedColumns": {//锁定列，只有开启scrollX时才生效
            "leftColumns": 0,
            "rightColumns": 0
        },
        "aoColumns": [
            {
                "orderable": false,
                "render": function (data, type, full, meta) {
                    return meta.row + 1;
                }
            }, {
                "orderable": false,
                "data": "bidUserName"
            }, {
                "orderable": false,
                "data": "workTime"
            },
            {
                "orderable": false,
                "data": "workTimeCost",
                "render": function (data, type, full, meta) {
                    return data.toFixed(2);
                }
            },
            {
                "orderable": false,
                "data": "commission"

            },
            {
                "orderable": false,
                "data": "allCost"
            },
            {
                "orderable": false,
                "data": "contractPercentage",
                "render": function (data, type, full, meta) {
                    var money = parseInt($("#money").val());
                    var cost = parseInt(full.allCost);
                    if (isNaN(money)) {
                        return "";
                    } else {
                        return ((cost / money) * 100).toFixed(2) + "%";
                    }
                }
            },
            {
                "orderable": false,
                "data": "joiners",
                "render": function (data, type, full, meta) {
                    if (data != null) {
                        return data.replace(/,/g, '<br/>');
                    } else {
                        return data;
                    }

                }
            },
            {
                "orderable": false,
                "data": "id",
                "render": function (data, type, full, meta) {
                    return data;
                }
            },
            {
                "orderable": false,
                "data": "remark",
                "render": function (data, type, full, meta) {
                    if (data.length > 10) {
                        return '<p title="' + data + '">' + data.substring(0, 9) + "......" + '</p>';
                    }
                    else {
                        return data ? data : "";
                    }
                }
            },
            {
                "orderable": false,
                "data": "status",
                "render": function (data, type, full, meta) {
                    if (data == 1) {
                        return "已中标";
                    } else {
                        return "未中标";
                    }
                }
            },
            {
                "orderable": false,
                "data": "createTime"
            }],
        "columnDefs": [{
            targets: [10], //第1，2，3列
            createdCell: function (td, cellData, rowData, row, col) {
                if (cellData == 1) {
                    $(td).parent().css("background-color", "#95e7bd")
                }
            }
        }, {
            targets: [8], //第1，2，3列
            createdCell: function (td, cellData, rowData, row, col) {
                var $td = $(td), id = $td.text();
                $td.empty().append(getUploadLab(id));
            }
        }]
    });

    /**
     * 附件
     * @returns
     */
    var dggUploader = $(".upload").dggUploader({
        fileId: $("#bidFieldId").val()//文件ID
        , uploadBaseUrl: uploadBaseUrl
        , isRemove: false
        , showIcon: true
    });
    dggUploader.findFiles($("#bidFieldId").val(), "bidFilePreview", 0, 0);//获取文件列表
});

function getUploadLab(id) {
    var str = "";
    str = '<div class="upload-bz" style="display:inline">'
        + '<input type="hidden" name="fileId" value="sccenter_general_' + id + '_scbidrecord_bid_bidFileId" id="bidFieldId' + id + '">'
        + '<ul class="data-warp" id="bidFilePreview' + id + '" style="display:inline">'
        + '<li class="upload-re">'
        + '<a href="javascript:void(0)" class="upload-button upload"></a>'
        + '<p>上传附件</p>'
        + '</li>'
        + '</ul>'
        + '</div>';
    var $upload = $(str);
    $upload.find('.upload').dggUploader({
        fileId: $upload.find('input[name="fileId"]').val(),//文件ID
        uploadBaseUrl: uploadBaseUrl,
        isRemove: false,
        showIcon: false
    }).findFiles($upload.find('input[name="fileId"]').val(), 'bidFilePreview' + id, 0, 0);
    $upload.find("li[class='upload-re']").remove();
    $upload.find('img').remove();
    $upload.find('a').css({'height': '40px'});
    return $upload[0];
}